package net.vistiyos.activities;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

import net.vistiyos.R;
import net.vistiyos.model.Hit;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

public class Details extends Activity {
	
	@Override
	  public void onCreate(Bundle icicle) {
	    super.onCreate(icicle);
	    setContentView(R.layout.details);
	    Bundle datos=getIntent().getExtras();
	    TextView nombre=(TextView)findViewById(R.id.name);
	    TextView size=(TextView)findViewById(R.id.size);
	    TextView extension=(TextView)findViewById(R.id.extension);
	    try {
			Hit objeto=Hit.deserializar(datos.getByteArray("details"));
			nombre.setText(objeto.getName());
			size.setText(objeto.getSize());
			extension.setText(objeto.getExtension());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	    /*
	    try{	
	    	Document doc=Jsoup.connect(objeto.getDetails().toString()).get();
	    	Element nodo=doc.getElementById("copy_paste_links");
	    	String url=nodo.text();
	    	mostrar.setText(url);
	    	TextView hosting=(TextView)findViewById(R.id.hosting);
	    	hosting.setText(getHostFromUrl(url));
	    }catch(IOException ex){
	    	
	    }*/
	  }
	
	private String getHostFromUrl(String url) {
	    try {
	      URI uri = new URI(url);
	      String host = uri.getHost();
	      if (host == null)
	        return null;

	      host = host.replaceAll("^www\\.", "");

	      int i = host.lastIndexOf('.');
	      if (i >= 0) {
	        int j = host.lastIndexOf('.', i - 1);
	        if (j >= 0)
	          host = host.substring(j + 1, host.length());
	      }
	      return host;
	    } catch (URISyntaxException urie) {
	      Log.e("getHostFromUrl", urie.getMessage());
	    }

	    return url;

	  }

}
